﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace SnmpForm.ApBatchConfig
{
    public class FrmApBatchConfig:Form
    {
        protected List<BusinessWrapper.Ap> m_listAsset = null;
        public FrmApBatchConfig()
        {
            InitializeComponent();
        }
    
        public FrmApBatchConfig(List<BusinessWrapper.Ap> list)
        {
            m_listAsset = list;

            InitializeComponent();
        }

        public delegate void UpdateStatus(BusinessWrapper.Ap ap, string status);
        public UpdateStatus updateStatus;
        public virtual void UpdateStatusMethod(BusinessWrapper.Ap ap, string strStatus)
        {
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // FrmApBatchConfig
            // 
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "FrmApBatchConfig";
            this.ResumeLayout(false);

            updateStatus = new UpdateStatus(UpdateStatusMethod);

        }

        public virtual BatchTask CreateTask(List<BusinessWrapper.Ap> aps)
        {
            BatchTask task = new BatchTask(this, aps);
            return task;
        }

        private Thread objThreadBatch = null;
        protected void StartApBatchTask()
        {
            if (objThreadBatch == null ||
                objThreadBatch.ThreadState == ThreadState.Stopped)
            {
                BatchTask taskBatch =
                    CreateTask(m_listAsset);
                objThreadBatch = new Thread(taskBatch.Run);
                objThreadBatch.Start();
            }
        }

        protected void StopApBatchTask()
        {
            if (objThreadBatch != null)
            {
                if (objThreadBatch.ThreadState != ThreadState.Stopped)
                {

                    objThreadBatch.Abort();
                    objThreadBatch = null;
                }
            }
        }
    }
}
